function setMessageId(id) { 
	window.external.SetValue("WWelcomeScreenDataSource", "CurrentMessageId", id);
}

function UpdatesCtrl($scope, $location, $http, $sce) {
	var json = window.external.GetValue("WWelcomeScreenDataSource", "UpdateMessagesJson");
	$scope.updates = angular.fromJson(json);
	if ($scope.updates.length == 0) {
		$scope.updates.push({title:$scope.localize('Updates', 'No Updates Available')});
	}
	for (var i = 0; i < $scope.updates.length; ++i) {
		if ($scope.updates[i].content)
		{
			$scope.updates[i].content = $scope.updates[i].content.replace(/(onclick=["'])/g, "$1setMessageId("+$scope.updates[i].id+");");
			$scope.updates[i].content = $scope.updates[i].content.replace(/\.\.\/\.\.\//g, "$archive$");
			$scope.updates[i].content = $scope.updates[i].content.replace(/\.\.\//g, $scope.updates[i].archive);
			$scope.updates[i].content = $scope.updates[i].content.replace(/\$archive\$/g, $scope.updates[i].archive + "../");
			$scope.updates[i].html = $sce.trustAsHtml($scope.updates[i].content);
		}
	};

	$scope.notify = window.external.GetValue("WWelcomeScreenDataSource", "IpmNotifyNew") ? true : false;
	$scope.notifyChange = function() { window.external.SetValue("WWelcomeScreenDataSource", "IpmNotifyNew", $scope.notify ? 1 : 0); };
	
	$scope.download = window.external.GetValue("WWelcomeScreenDataSource", "IpmAutoDownload") ? true : false;
	$scope.downloadChange = function() { window.external.SetValue("WWelcomeScreenDataSource", "IpmAutoDownload", $scope.download ? 1 : 0); };
}
